#include "Nixie.h"

unsigned char Nixie_Buf[9] = {0,10,10,10,10,10,10,10,10};
//unsigned char NixieTable[] = {0X3F,0X06,0X5B,0X4F,0X66,0X6D,0X7D,0X07,0X7F,0X6F,0X77,0X7C,0X39,0X5E,0X79,0X71,0X00};
unsigned char NixieTable[] = {0X3F,0X06,0X5B,0X4F,0X66,0X6D,0X7D,0X07,0X7F,0X6F,0X00,0X40};

void Nixie_SetBuf(unsigned char location,unsigned char NUM)
{
	Nixie_Buf[location] = NUM;
}

void Nixie_Scan(unsigned char location,unsigned char LED_Data)
{
	P0 = 0x00;
	switch (location){
		case 8://LED1
			P2_4 = 0;P2_3 = 0;P2_2 = 0;
			break;
		case 7:
			P2_4 = 0;P2_3 = 0;P2_2 = 1;
			break;
		case 6:
			P2_4 = 0;P2_3 = 1;P2_2 = 0;
			break;
		case 5:
			P2_4 = 0;P2_3 = 1;P2_2 = 1;
			break;
		case 4:
			P2_4 = 1;P2_3 = 0;P2_2 = 0;
			break;
		case 3:
			P2_4 = 1;P2_3 = 0;P2_2 = 1;
			break;
		case 2:
			P2_4 = 1;P2_3 = 1;P2_2 = 0;
			break;
		case 1:
			P2_4 = 1;P2_3 = 1;P2_2 = 1;
			break;
	}
	P0 = NixieTable[LED_Data];
}

void Nixie_Loop(void)
{
	static unsigned char i = 1;//i从1开始，是指第一个数码管
	Nixie_Scan(i,Nixie_Buf[i]);
	i++;
	if (i >= 9)
	{
		i = 1;
	}
}
